package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.rpframework.core.BaseService;
import com.rpframework.utils.NumberUtils;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.ICategoryDao;
import com.rpframework.website.device.domain.Category;
import com.rpframework.website.device.domain.GoodsPro;

@Service
public class CategoryService extends BaseService {
	public @Resource ICategoryDao iDao;

	public Pager<Category> getPager(Pager<Category> pager) {
		long startTime = System.currentTimeMillis();
		List<Category> list = iDao.doPager(this.packageMyBatisParam(pager));

		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}
	
	
	
	


	public boolean doSaveOrUpdate(Category t) {
		if(t == null) {
			throw new IllegalArgumentException("非法参数!");
		}
		if(StringUtils.isBlank(t.getName())){
			throw new IllegalArgumentException("非法参数!");
		}
		if(StringUtils.isBlank(t.getUrlList().toString())){
			throw new IllegalArgumentException("非法参数!");
		}
		
		if(NumberUtils.isValid(t.getId())) {
			Category DBUtils = iDao.select(t.getId());
			Assert.notNull(DBUtils, "更新时找不到实体 " + t.getId());
			if(t.getUrlList()==null){
				t.setUrlList(DBUtils.getUrlList());
			}
			
			return iDao.update(t);
		}
		
		return iDao.insert(t);
	}



	
	
	
	
}
